<?php

include_once('top.php');

$employees = fetch_all(
		"SELECT USER.First_name , USER.Last_name , USER.Email , COUNT(CERTIFICATION.User) AS Certifications "
		. "FROM USER LEFT JOIN CERTIFICATION "
		. "ON USER.Email = CERTIFICATION.User "
		. "WHERE USER.Type = 'R' "
		. "GROUP BY USER.Email "
		. "ORDER BY USER.Last_name ASC ");

for ($i = 0; $i < count($employees); $i++) {
	$employees[$i]['Name'] = "{$employees[$i]['First_name']} {$employees[$i]['Last_name']}";
}

?>

<html>
<head>
	<title>GT Project Manager - Employee Management</title>
	<link rel="stylesheet" type="text/css" href="main.css" />
	<link rel="stylesheet" type="text/css" href="inner.css" />
</head>
<body>
	<table cellspacing="0" cellpadding="0" id="main">
		<tr><td id="title">
			Employee Management
			<div class="nav">
				<a href="login.php?action=logout">Log Out</a>
			</div>
		</td></tr>
		<tr>
			<td>
				<table class="subsection summary" cellspacing="0" cellpadding="0">
					<tr><td class="title" colspan="4">
						Employee List
						<hr size="1" />
						<div class="link">
							<a href="employee_info.php">New Employee</a>
						</div>
					</td></tr>
					<tr>
						<th>Name</th>
						<th>Email</th>
						<th>Certifications</th>
					</tr>
					<?php
					foreach($employees as $employee) {
					?>
					<tr>
						<td><a href="view_employee.php?user=<?php echo $employee['Email'] ?>"><?php echo $employee['Name'] ?></a></td>
						<td><?php echo $employee['Email'] ?></td>
						<td><?php echo $employee['Certifications'] ?></td>
					</tr>
					<?php
					}
					?>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>